﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml.Serialization;

namespace XEvents.Library
{
    public class PackageCollection : List<Package>
    {
        public PackageCollection(IEnumerable<Package> p)
            : base(p)
        { }

        public Package this[string name]
        {
            get
            {
                Dictionary<string, Package> dict = this.ToDictionary(n => n.Name, n => n);
                if (dict.Keys.Contains(name))
                    return dict[name];
                else
                    return null;
            }
        }

        public PackageCollection PackagesWithEvents
        {
            get
            {
                return new PackageCollection(from p in this
                                             where p.Events.Count > 0
                                             select p);
            }
        }

        public PackageCollection PackagesWithTargets
        {
            get
            {
                return new PackageCollection(from p in this
                                             where p.Targets.Count > 0
                                             select p);
            }
        }
    }
}
